package co.fitstart.entity.course.schedule;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import com.demo2do.core.utils.DateFormatUtils;
import com.demo2do.core.utils.DateUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import co.fitstart.entity.user.UserAccount;

/**
 * 
 * @author haiyan_xiao
 *
 */
@Entity
@Table(name = "schedule_sms_notice")
@JsonIgnoreProperties(value={"hibernate_lazy_initializer","handler","fieldHandler"})
public class ScheduleSmsNotice {
    
    @Id
    @GeneratedValue
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    private CourseSchedule courseSchedule;
    
    /** 学员手机号 */
    private String mobile;
    
    /** 学员手机号 */
    private String openid;
    
    /** 门店 */
    private String site;
    
    /** 教练 */
    private String coach;
    
    /** 上课日期 */
    private String occurDate;
    
    /** 上课时间 */
    private String occurHour;
    
    /** 课程类型 */
    private String courseType;
    
    private String courseName;
    
    /** 发送时间 */
    private Date sendTime;
    
    /** 是否发送 */
    @Column(name = "is_sent")
    private boolean sent;
    
    @Column(name = "is_disabled")
    private boolean disabled;
    
    public ScheduleSmsNotice() {
        
    }
    
    public ScheduleSmsNotice(UserAccount userAccount, CourseSchedule courseSchedule) {
    	if(userAccount != null) {
        	this.openid = userAccount.getValue();
    	}
        this.courseSchedule = courseSchedule;
        this.mobile = courseSchedule.getStudent().getMobile();
        this.site = courseSchedule.getSite().getName();
        this.coach = courseSchedule.getCoach().getName();
        this.occurDate = DateFormatUtils.format(courseSchedule.getOccurDate(), "MM/dd");
        this.occurHour = courseSchedule.getOccurHour();
        this.courseType = courseSchedule.getCourseType().getOther();
        this.courseName = courseSchedule.getCourseName();
        if(this.site.equalsIgnoreCase("花木陆悦坊店")) {
        	this.sendTime = org.apache.commons.lang3.time.DateUtils.addHours(DateUtils.parseDate(DateFormatUtils.format(courseSchedule.getOccurDate(), "yyyy-MM-dd") + " " + courseSchedule.getOccurHour(), "yyyy-MM-dd HH:mm"), -3);
        } else {
        	this.sendTime = org.apache.commons.lang3.time.DateUtils.addHours(DateUtils.parseDate(DateFormatUtils.format(courseSchedule.getOccurDate(), "yyyy-MM-dd") + " " + courseSchedule.getOccurHour(), "yyyy-MM-dd HH:mm"), -2);
        }
        
        this.sent = false;
        this.disabled = false;
    }
    
    /**
     * 
     * @return
     */
    public ScheduleSmsNotice disable() {
        this.disabled = true;
        
        return this;
    }

    /**
     * @return the id
     */
    public Long getId() {
        return id;
    }

    /**
     * @return the courseSchedule
     */
    public CourseSchedule getCourseSchedule() {
        return courseSchedule;
    }

    /**
     * @return the mobile
     */
    public String getMobile() {
        return mobile;
    }

    /**
     * @return the site
     */
    public String getSite() {
        return site;
    }

    /**
     * @return the coach
     */
    public String getCoach() {
        return coach;
    }

    /**
     * @return the occurDate
     */
    public String getOccurDate() {
        return occurDate;
    }

    /**
     * @return the occurHour
     */
    public String getOccurHour() {
        return occurHour;
    }

    /**
     * @return the courseType
     */
    public String getCourseType() {
        return courseType;
    }
    
    public String getCourseName() {
		return courseName;
	}

    /**
     * @return the sendTime
     */
    public Date getSendTime() {
        return sendTime;
    }

    /**
     * @return the sent
     */
    public boolean isSent() {
        return sent;
    }

    /**
     * @return the disabled
     */
    public boolean isDisabled() {
        return disabled;
    }

    /**
     * @param id the id to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * @param courseSchedule the courseSchedule to set
     */
    public void setCourseSchedule(CourseSchedule courseSchedule) {
        this.courseSchedule = courseSchedule;
    }

    /**
     * @param mobile the mobile to set
     */
    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    /**
     * @param site the site to set
     */
    public void setSite(String site) {
        this.site = site;
    }

    /**
     * @param coach the coach to set
     */
    public void setCoach(String coach) {
        this.coach = coach;
    }

    /**
     * @param occurDate the occurDate to set
     */
    public void setOccurDate(String occurDate) {
        this.occurDate = occurDate;
    }

    /**
     * @param occurHour the occurHour to set
     */
    public void setOccurHour(String occurHour) {
        this.occurHour = occurHour;
    }

    /**
     * @param courseType the courseType to set
     */
    public void setCourseType(String courseType) {
        this.courseType = courseType;
    }
    
    public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

    /**
     * @param sendTime the sendTime to set
     */
    public void setSendTime(Date sendTime) {
        this.sendTime = sendTime;
    }

    /**
     * @param sent the sent to set
     */
    public void setSent(boolean sent) {
        this.sent = sent;
    }

    /**
     * @param disabled the disabled to set
     */
    public void setDisabled(boolean disabled) {
        this.disabled = disabled;
    }
    
    public String getOpenid() {
		return openid;
	}
    
    public void setOpenid(String openid) {
		this.openid = openid;
	}
}
